import { defineStore } from "pinia";
import { AppState } from "../interface";
import piniaPersistConfig from "@/stores/helper/persist";

export const useAppStore = defineStore({
  id: "AppStore",
  state: (): AppState => ({
    // token
    token: "",
    // imToken
    imToken: "",
    // 用户id
    userId: "",
    // 用户姓名
    userName: "",
    // 用户电话
    userPhone: "",
    // 用户头像
    userAvatar: "",
    // 用户认证标识
    flagIdentity: "",
    // 企业用户标识
    flagCompany: "",
    // userInfo
    userInfo: ""
  }),
  getters: {
    getUserAvatar: (state): string => {
      return state.userAvatar;
    },
    getUserId: (state): string => {
      return state.userId;
    },
    getUserToken: (state): string => {
      return state.token;
    },
    getFlagCompany: (state): string => {
      return state.flagCompany;
    }
  },
  actions: {
    setToken(token: string) {
      this.token = token;
    },
    setImToken(token: string) {
      this.imToken = token;
    },
    setUserId(userId: string) {
      this.userId = userId;
    },
    setUserName(userName: string) {
      this.userName = userName;
    },
    setUserPhone(userPhone: string) {
      this.userPhone = userPhone;
    },
    setUserAvatar(userAvatar: string) {
      this.userAvatar = userAvatar;
    },
    setFlagIdentity(flagIdentity: string) {
      this.flagIdentity = flagIdentity;
    },
    setFlagCompany(flagCompany: string) {
      this.flagCompany = flagCompany;
    },
    setUserInfo(userInfo: any) {
      this.userInfo = userInfo;
    }
  },
  persist: piniaPersistConfig("AppStore")
});
